package com.liu.fresh.listener;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.liu.fresh.util.StringUtil;
/**
 * 用来创建文件上传所需的目录
 * 源辰信息
 * @author liu
 * @date 2020年4月3日
 */
@WebListener
public class InitApplicationListener implements ServletContextListener{
	@Override
	public void contextDestroyed(ServletContextEvent sce) {//销毁的方法
		
	}
	@Override
	public void contextInitialized(ServletContextEvent sce) {//初始化的方法
		String path = "images/goods";//路径在tomcat-> webapps
		
		String temp = sce.getServletContext().getInitParameter("uploadpath");
		if(!StringUtil.checkNull(temp)){
			path = temp;
		}
		
		String basePath = sce.getServletContext().getRealPath("/");
		File fl = new File(basePath, "../" + path);
		if(!fl.exists()){
			fl.mkdirs();
		}
	}
	
}
